home *** CD-ROM | disk | FTP | other *** search
- <?php
-
- /* Copyright (C) 2003 Adam Tow
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-
- function RunWithParams($methodName, $params)
- {
- global $_CONF;
-
- if(class_exists("SCPT_Script_Handler")) {
- switch($methodName)
- {
- case "new":
- return New_Album($params);
-
- case "upload":
- return Upload($params);
-
- case "action":
- if($params["action"]) {
- if($params["selected"] && is_array($params["selected"]) && count($params["selected"]) > 0) {
- $methodName = $params["action"];
-
- $scriptHandler = new SCPT_Script_Handler;
- $scriptPath = $params["path_service"] . "scripts/iPhoto.scpt";
-
- return $scriptHandler->RunScript($scriptPath, $methodName, $params);
- } else {
- return ScriptErrorResponse("", $params["locale"]["errNoSelectedImages"]);
- }
- } else {
- return ScriptErrorResponse("", $params["locale"]["errInvalidParameters"]);
- }
- break;
-
- default:
- $scriptHandler = new SCPT_Script_Handler;
- $scriptPath = $params["path_service"] . "scripts/iPhoto.scpt";
-
- return $scriptHandler->RunScript($scriptPath, $methodName, $params);
- break;
-
- }
- } else {
- return ScriptErrorResponse("", $_CONF["locale"]->GetString("errScriptHandlerNotFound"));
- }
- }
-
-
-
- function New_Album($params)
- {
- $scriptHandler = new SCPT_Script_Handler;
-
- // Make sure that an album with this name doesn't already exist
-
- $albumName = $params["album"];
- $cmd = "tell application \"iPhoto\" to return count of (every album whose name is \"$albumName\")";
- $pipe = popen("osascript -e '$cmd'", "r");
- while($s = fgets($pipe, 1024)) $result .= $s;
- pclose($pipe);
-
- if($result != 0)
- return ScriptErrorResponse("", $params["locale"]["errAlbumNameInUse"]);
-
- // Places the file uploads into a temp directory. We'll add them to the iPhoto Library
-
-
- }
-
-
-
- function Upload($params)
- {
- for($i = 1; $i <= 5; $i++) {
- $filename = "img" . $i;
-
- if ($_FILES[$filename] != "" && !$_FILES[$filename]["error"]) {
- $newFilename = "/tmp/" . $_FILES[$filename]['name'];
-
- if($newFilename != "/tmp/") {
- copy($_FILES[$filename]['tmp_name'], $newFilename) or die("Couldn't copy the file!");
-
- // Set the filename
-
- $params["filename"] = $newFilename;
-
- // Call the iPhoto AppleScript, which will handle importing the files
-
- $scriptHandler = new SCPT_Script_Handler;
- $scriptPath = $params["path_service"] . "scripts/iPhoto.scpt";
-
- $result = $scriptHandler->RunScript($scriptPath, "import", $params);
- }
- }
- }
-
- return $result;
- }
-
-
- ?>